<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资金转出记录</title>
 <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body >
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
<form id="editNotes_form" style="display: none;">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="field">
                    <textarea name="notesEdit" id="notesEdit" class="ui-textarea l-textarea"
                              rows="4" cols="60" style="width: 240px;" validate="{required:false}"></textarea>
                </div>
            </div>
        </div>
</form>
 <!-- (财务多条) <button id="addRow" class="sq-button sq-button-round" >添加行</button> -->
  <input id="start_addrRow_button" name="start_Nm_add" type="text" style="display:none" value="">
</div>
	<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
var grid = null;
 //加载资金类型
$(function(){
	var FundConfirmFrozenListJSON = [];
	 <c:if test="${not empty FundConfirmFrozenListJSON}"> FundConfirmFrozenListJSON = ${FundConfirmFrozenListJSON}; </c:if>
//确认转出
frameElement.dialog.onModifyFundFrozen = function () {
	onModifyFrozen();
};
//资金id
var fund_Id = '${fundId}';
/*(财务多条) var g_add_id;
var g_add_userid;
var g_add_userNm; */
//转出资金
var fundAmt = '${fundAmt}';

grid = $("#ligergrid1").ligerGrid({
    url: '<%=path%>/capital/capFundOutLog/initfundList.do',
    parms: {fund_Id:fund_Id,fundAmt:fundAmt}, 
    method: 'get',
    columns: [
        {display: '资金编号', name: 'fundId', width: 130, align: 'center', enabledSort: false,
        	 render: function (item) {
  			   if(StringUtils.isNotEmpty(item.fundIdCdNm)){
  				   return  item.fundIdCdNm;
  			   }
         }	
        },
        {display: '转出类型',name:'outTypCd', width: 100,
        	editor: {
                type: 'select',
                data: FundConfirmFrozenListJSON,
                valueField: 'key',
                textField: 'value'
            },
            valueField: 'outTypCd',
            textField: 'outTypCdNm',
            render: function (item) {
        			   if(StringUtils.isEmpty(item.outTypCd)){
        				   item.outTypCdNm="请选择类型！";
        				   return '请选择类型<i class="ico_flasher"></i>';
        			   }else{
        				   return item.outTypCdNm
        			   }
               }	
        },
        {display: '转出时间', name: 'outTm', width: 100, align: 'center', enabledSort: false, 
        	editor: {type: 'date'},
            render: function(rowdata, index, value){
            	//debugger;
                if (!value) {
                    var nowDate = new Date().Format('yyyy-MM-dd')
                    rowdata.CustomerDate = nowDate
                    return nowDate
                } else {
                    return  renderDate2(value);
                }
            }
        },
        {display: '操作人工号', name: 'optUsrId', minWidth: 50, align: 'center', enabledSort: false,
        	/* (财务多条)render: function (item) {
 			   if(StringUtils.isNotEmpty(item.optUsrId)){
 				    g_add_userid=item.optUsrId;
				   return item.optUsrId;
 			   } 
        }	 */
        },
        {display: '操作人名称', name: 'optUsrNm', minWidth: 90, align: 'left', enabledSort: false,
        	/* (财务多条)render: function (item) {
  			   if(StringUtils.isNotEmpty(item.optUsrNm)){
  				    g_add_userNm=item.optUsrNm;
				   return item.optUsrNm;
  			   }
            }*/
        },
        {display: '转出金额', name: 'outAmt', minWidth: 90, align: 'left', enabledSort: false,
        	  editor: {
                  type: 'number'
                  },
                  render: function (rowdata, index, value) {
                      return '&yen;' + FormatMoney(rowdata.outAmt / 100);
                  }
        },
        {display: '剩余可转金额', name: 'outAmtfund', minWidth: 110, align: 'left', enabledSort: false,
                render: function (rowdata, index, value) {
                    return '&yen;' + FormatMoney(rowdata.outAmtfund / 100);
                }
      },
        {display: '转出备注', name: 'outRem', width: 100, align: 'left', enabledSort: false,
                  render: function (rowdata, index, value) {
                	  var h;
                	  if(StringUtils.isEmpty(rowdata.outRem)){
                		  h='<div onclick="editNotes(event, grid.rows['+index+'])">&nbsp;</div>';  
                	     }else{
                	      h = '<div onclick="editNotes(event, grid.rows['+index+'])">'+rowdata.outRem+'</div>';
                	     }
                	  return h;  
                	  
                  }
        },
    ],
    onBeforeEdit: function (e) {
    /*  alert(JSON.stringify(e));  */
       //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
		if (e.column.name=="outAmt") {
			//判断是否可以继续转出
		    if (e.record.outAmtfund == 0) {
		        e.column.editor.readonly = true;
		    }else{
		        e.column.editor.readonly = false;
		    };
		};
        if(e.column.name=="outAmt"){
          e.value = e.value / 100
         }
    }, 
    onBeforeSubmitEdit: function (e) {
        if (e.column.name == "outAmt") {
        	e.value = e.value * 100
        	if(e.value>e.record.outAmtfund){
        		$.ligerDialog.SQalert({content:"超出剩余可转金额！", SQ_type: "error"});
        	}
        }
        
    },
   /*(财务多条) onAfterShowData : function (eData) {
    	debugger;
    	alert(eData.rows[0].isNO);
        if (eData.rows[0].isNO==0||eData.rows[0].outAmtfund==0) {
        	$("#start_addrRow_button").attr("value", 1);
        }
        
    },*/
    enabledEdit: true,
    root: 'rows',
    record: 'total',
    hideLoadButton: true,
    width: '100%',
    checkbox: true,
    rownumbers: true,
    usePager: true,//不需要分页
    isScroll: true,//要不要滚动条
    allowUnSelectRow: true,
    alternatingRow: true,//
    delayLoad: false, //需延时加载
    pageSize: 10,//==
   // height: '100%',//==
    heightDiff: -2,//==
    allowHideColumn:false//设置他的列不可选择
});
//添加行数据(财务多条)  (不要删除  后面财务如果想要多条记录形式 可直接使用)
/* $('#addRow').on('click', function(event) {
	if(StringUtils.isNotEmpty($('#start_addrRow_button').val())){
		$.ligerDialog.SQalert({content:"请编辑当前数据！", SQ_type: "error"});
	}else{
		   event.preventDefault();
		    grid.addRow({fundId: g_add_id,
		    	         outTypCd:'', 
		    	         outTm: '',
		    	         optUsrId:g_add_userid,
		    	         optUsrNm:g_add_userNm, 
		    	         outAmt: '',
		    	         outAmtfund:'', 
		    	         outRem:''
		  });
	    }
    }); */
});
function  onModifyFrozen(){
       var data= grid.getData();
      $.ajax({
			type: 'post',
			dataType:'json',
			data:{Param:JSON.stringify(data)},
		    url: '<%=path%>/capital/capFundOutLog/addModifyFrozen.do',
			success:function(msg){
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success",onClosed:function(){
						 frameElement.dialog.close();
					 }});
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
}
//格式化时间
function renderDate(value) {
    var dateStr = "";
    if (null != value) {
        var date = new Date(value);
        dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
    }
    return dateStr;
}
//格式化时间
function renderDate2( value) {
    var dateStr = "";
    if (null != value) {
        var date = new Date(value);
        dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
    }
    return dateStr;
}
//备注弹出框
function editNotes(event, rowData) {
    var oldNote = rowData.outRem,
        $notesEdit = $('#notesEdit');
    $notesEdit.val(rowData.outRem);
    var onOk = function (item, Dialog) {
        rowData.outRem = $notesEdit.val();
        grid.updateRow(rowData);
        Dialog.hide();
    };
    var onCancel = function (item, Dialog) {
        Dialog.hide();
    };
    $.ligerDialog.SQopen({
        width: 300,
        title : '备注',
        target : $('#editNotes_form'),
        buttons: [{
                text: "确认", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
            },
            {
                text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
            }
        ]
    });
}
</script>
</body>
</html>
